<html>
    <head>
        <title>Sign in</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
        <script src="http://passport.cnblogs.com/scripts/jsencrypt.min.js"></script>
        <script src="http://www.gongjuji.net/Content/files/jquery.md5.js"></script>
        <script src="/resources/static/js/aes_1.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/Base64/1.1.0/base64.min.js"></script>
        <script src="/resources/static/js/str2byte.js"></script>
        <script>
            function checkForm() {
            var RSACrypto = new JSEncrypt();
            var token = document.getElementById("token");
            var dataArr = token.value.split("-----");
            token.value = dataArr[0];
            var pub_key = dataArr[1];
            var input_pwd = document.getElementById('input_pwd');
            var encoded_pwd = document.getElementById('encoded_pwd');
            if(input_pwd==null){
                alert("error input");
                return false;
            }
            encoded_pwd.value = input_pwd;
            var obj = $("#test_form").serialize();
            var md5str = $.md5(obj);
            RSACrypto.setKey(pub_key);
            var signiture = RSACrypto.encrypt(md5str);
            <!--得到签名siguniture-->

            <!--生成动态AES密钥-->
            <!--首先获取uername-->
            var username = document.getElementById("userName").value;
            var timestamp = (new Date()).getTime();
            var timestamp1 = username+timestamp;
            var sourcekey = timestamp1.substring(0,16);

            var tmp = stringToByte(obj);
            console.log(tmp);
            <!--AES 加密 jsonstr -->
            var aesKey= sourcekey;
            var key = aesKey;
            var iv_tmp = stringToByte("12345678abcdefgh")
            var bodystr = CryptoJS.AES.encrypt(obj, key, {
            iv: iv_tmp,
                mode: CryptoJS.mode.CBC,
                padding: CryptoJS.pad.Pkcs7
            });
            var bodystring=bodystr.toString();

            <!-- 获取AESKeyStr -->
<!--            var AESKeyStr = $.md5(aesKey);-->
            var AESKeyStr = btoa(aesKey);
            <!-- AESKeySecret -->
            var AESKeySecret = RSACrypto.encrypt(AESKeyStr);

            data = {"Authoration":signiture,"SecurityKey":AESKeySecret,"bodyStr":bodystring,"Timestamp":timestamp,"token":token.value};
            $.ajax({
            url: 'login',
            data: JSON.stringify(data),
            dataType: "html",
            type: "post",
            success: function(result) {
                console.log(result)
            }
            });
            }


        </script>
<!--        <script>-->
<!--            var decrypt = CryptoJS.AES.decrypt(data2, key, {-->
<!--                iv: CryptoJS.enc.Utf8.parse(aseKey.substr(0,16)),-->
<!--                mode: CryptoJS.mode.CBC,-->
<!--                padding: CryptoJS.pad.Pkcs7-->
<!--            });-->
<!--            var data3=JSON.parse(decrypt.toString(CryptoJS.enc.Utf8));-->
<!--        </script>-->
<!--        <script type="text/javascript">-->
<!--            //var password = document.getElementById("password").value;-->
<!--            var password="hello";-->
<!--            var md5password = hex_md5(password);-->
<!--        </script>-->
    </head>
    <body>

        <!--表单只提交有name属性的-->
        <form id='test_form' action="/login" method="post"><!--onsubmit='return checkForm()'-->
            用户名：<input type="text" id="userName" name="userName"/>
            密码：<input type="password"  id="input_pwd" name="password"/>
            <input type='hidden' id='encoded_pwd' value=''/>
            <!--token获取时间戳避免多次提交--><!--获取公钥用于加密-->
<!--            <input type="hidden" name="Authoration"></input>-->
<!--            <input type="hidden" name="SecurityKey"></input>-->
<!--            <input type="hidden" name="bodyStr"></input>-->
            <input type="hidden" name="token" id="token" value="{{.}}"/>
            <button type='button' onclick="checkForm()">Sign in</button>
        </form>
    </body>
</html>